package han.chensing.latos.game.elements.effect;

import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import han.chensing.latos.res.Res;
import han.chensing.latos.game.elements.LatosElement;

public class HitEffect extends LatosElement {
    public static boolean corruptEffect=false;
    public enum Type{
        Perfect,Good
    }
    private float totalTime=0;
    private final Animation<TextureRegion> animation;
    public HitEffect(Type type,int x,int y){
        super(Res.getInstance().get("effectEmpty",TextureRegion.class));
        switch (type){
            default:
            case Perfect:
                TextureRegion[] perfectRegion =
                        corruptEffect?
                                (Res.getInstance().get("effectCopPerfect",
                                        TextureRegion[].class)):
                                (Res.getInstance().get("effectPerfect",
                                TextureRegion[].class));
                animation=new Animation<>(0.0065f,perfectRegion);
                break;
            case Good:
                TextureRegion[] goodRegion =
                        corruptEffect?
                                (Res.getInstance().get("effectCopGood",
                                        TextureRegion[].class)):
                                (Res.getInstance().get("effectGood",
                                        TextureRegion[].class));
                animation=new Animation<>(0.0065f,goodRegion);
                break;
        }
        setRotation(corruptEffect?45:0);
        setPosition(x-getRegionHeight()/2f,y-getRegionHeight()/2f);
        setScale(corruptEffect?1.4f:1.5f);
        animation.setPlayMode(Animation.PlayMode.NORMAL);
        setScale(1.8f);
    }

    @Override
    public void lAct(float delta, float currentTime) {
        totalTime+=delta;
        if (totalTime>=animation.getAnimationDuration()){
            died=true;
        }
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {
        TextureRegion keyFrame = animation.getKeyFrame(totalTime);
        batch.setColor(1,1,1,.9f);
        batch.draw(keyFrame,getX(),getY(),getOriginX(),getOriginY(),
                getWidth(),getHeight(),getScaleX(),getScaleX(),getRotation());
        batch.setColor(1,1,1,1);
    }

}